import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';
import 'package:meal/constant/sizes.dart';
import 'package:meal/route/route.dart';
import 'package:meal/utils/colors.dart';
import 'package:meal/utils/styles.dart';
import 'package:meal/utils/tools.dart';

///
/// 推荐活动
///
class MarketRecommendActivity extends StatefulWidget {
  final bool isAll;

  const MarketRecommendActivity({Key? key, this.isAll = true}) : super(key: key);

  @override
  State<MarketRecommendActivity> createState() => _MarketRecommendActivityState();
}

class _MarketRecommendActivityState extends State<MarketRecommendActivity> {
  TextStyle get style {
    return StylesUtils.customTextStyle(fontSize: Sizes.default16, color: ColorsUtils.color363);
  }

  TextStyle get defaultStyle {
    return StylesUtils.customTextStyle(fontSize: Sizes.default13, color: ColorsUtils.color797);
  }

  TextStyle get whiteStyle {
    return StylesUtils.customTextStyle(fontSize: Sizes.default12);
  }

  TextStyle get btnStyle {
    return StylesUtils.customTextStyle(fontSize: Sizes.default15, color: ColorsUtils.color363);
  }

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Column(
        children: [
          Container(
            margin:
                const EdgeInsets.symmetric(vertical: Sizes.default10, horizontal: Sizes.default20),
            decoration: BoxDecoration(
                color: Colors.white, borderRadius: BorderRadius.circular(Sizes.default15)),
            child: ListBody(
              children: [
                GFImageOverlay(
                  height: 92,
                  borderRadius: const BorderRadius.only(
                      topLeft: Radius.circular(Sizes.default15),
                      topRight: Radius.circular(Sizes.default15)),
                  image: ToolsUtils.assetImage('activity.jpg'),
                ),
                Container(
                  padding: const EdgeInsets.only(
                      left: Sizes.default15, right: Sizes.default15, bottom: Sizes.default25),
                  child: Column(
                    children: [
                      SizedBox(
                        height: Sizes.default45,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(
                              '暑假优惠大酬宾',
                              style: style,
                            ),
                            Container(
                              constraints: const BoxConstraints.expand(
                                  width: Sizes.default70, height: Sizes.default20),
                              decoration: BoxDecoration(
                                  color: ColorsUtils.rgba(0, 102, 204, 1),
                                  borderRadius: BorderRadius.circular(Sizes.default10)),
                              alignment: Alignment.center,
                              child: Text.rich(TextSpan(children: [
                                WidgetSpan(
                                    child: ToolsUtils.getUrlSvg(
                                        'https://cdn7.axureshop.com/demo/1525603/images/团购管理/u2984.svg',
                                        width: Sizes.default13,
                                        height: Sizes.default13)),
                                TextSpan(text: '进行中', style: whiteStyle)
                              ])),
                            )
                          ],
                        ),
                      ),
                      Container(
                        alignment: Alignment.centerLeft,
                        child: Text(
                          '推荐商品：20 个',
                          style: defaultStyle,
                        ),
                      ),
                      Container(
                        alignment: Alignment.centerLeft,
                        margin: const EdgeInsets.symmetric(vertical: Sizes.default10),
                        child: Text(
                          '活动日期：2023-03-10 至 2023-09-11',
                          style: defaultStyle,
                        ),
                      ),
                      Container(
                        alignment: Alignment.centerLeft,
                        child: Text(
                          '备注说明：每人限购一份',
                          style: defaultStyle,
                        ),
                      ),
                      Container(
                        alignment: Alignment.centerLeft,
                        margin: const EdgeInsets.only(top: Sizes.default10),
                        child: Text(
                          '创建时间：2023-03-10 09:11:12',
                          style: defaultStyle,
                        ),
                      ),
                    ],
                  ),
                ),
                SizedBox(
                  height: Sizes.default44,
                  child: Row(
                    children: [
                      Expanded(
                          child: TextButton(
                              onPressed: () {
                                pauseActivity();
                              },
                              child: Text(
                                '暂停活动',
                                style: style,
                              ))),
                      Expanded(
                          child: TextButton(
                              onPressed: gotoView,
                              child: Text(
                                '查看详情',
                                style: style,
                              ))),
                    ],
                  ),
                )
              ],
            ),
          ),
          Container(
            margin:
            const EdgeInsets.only(left: Sizes.default20, right: Sizes.default20, bottom: Sizes.default10),
            decoration: BoxDecoration(
                color: Colors.white, borderRadius: BorderRadius.circular(Sizes.default15)),
            child: ListBody(
              children: [
                GFImageOverlay(
                  height: 92,
                  borderRadius: const BorderRadius.only(
                      topLeft: Radius.circular(Sizes.default15),
                      topRight: Radius.circular(Sizes.default15)),
                  image: ToolsUtils.assetImage('activity2.jpg'),
                ),
                Container(
                  padding: const EdgeInsets.only(
                      left: Sizes.default15, right: Sizes.default15, bottom: Sizes.default25),
                  child: Column(
                    children: [
                      SizedBox(
                        height: Sizes.default45,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(
                              '寒假钜惠',
                              style: style,
                            ),
                            Container(
                              constraints: const BoxConstraints.expand(
                                  width: Sizes.default70, height: Sizes.default20),
                              decoration: BoxDecoration(
                                  color: ColorsUtils.rgba(153, 153, 153, 1),
                                  borderRadius: BorderRadius.circular(Sizes.default10)),
                              alignment: Alignment.center,
                              child: Text.rich(TextSpan(children: [
                                WidgetSpan(
                                    child: ToolsUtils.getUrlSvg(
                                        'https://cdn7.axureshop.com/demo/1525603/images/团购管理/u2984.svg',
                                        width: Sizes.default13,
                                        height: Sizes.default13)),
                                TextSpan(text: '已暂停', style: whiteStyle)
                              ])),
                            )
                          ],
                        ),
                      ),
                      Container(
                        alignment: Alignment.centerLeft,
                        child: Text(
                          '推荐商品：20 个',
                          style: defaultStyle,
                        ),
                      ),
                      Container(
                        alignment: Alignment.centerLeft,
                        margin: const EdgeInsets.symmetric(vertical: Sizes.default10),
                        child: Text(
                          '活动日期：2023-03-10 至 2023-09-11',
                          style: defaultStyle,
                        ),
                      ),
                      Container(
                        alignment: Alignment.centerLeft,
                        child: Text(
                          '备注说明：每人限购一份',
                          style: defaultStyle,
                        ),
                      ),
                      Container(
                        alignment: Alignment.centerLeft,
                        margin: const EdgeInsets.only(top: Sizes.default10),
                        child: Text(
                          '创建时间：2023-03-10 09:11:12',
                          style: defaultStyle,
                        ),
                      ),
                    ],
                  ),
                ),
                SizedBox(
                  height: Sizes.default44,
                  child: Row(
                    children: [
                      Expanded(
                          child: TextButton(
                              onPressed: () {
                                pauseActivity('是否恢复此活动?');
                              },
                              child: Text(
                                '恢复活动',
                                style: style,
                              ))),
                      Expanded(
                          child: TextButton(
                              onPressed: gotoView,
                              child: Text(
                                '查看详情',
                                style: style,
                              ))),
                    ],
                  ),
                )
              ],
            ),
          ),
        ],
      ),
    );
  }

  void pauseActivity([String title = '是否暂停此活动?']) async {
    final dialog = BrnDialog(
        verticalDivider: const VerticalDivider(
          width: 1.0,
          color: Colors.black,
        ),
        divider: const Divider(
          height: 1.0,
          color: Colors.black,
        ),
        contentWidget: ListBody(
          children: [
            Container(
              padding: const EdgeInsets.symmetric(vertical: Sizes.default15),
              alignment: Alignment.center,
              child: Text(
                title,
                style: StylesUtils.customTextStyle(
                    color: ColorsUtils.color000, fontSize: Sizes.default18),
              ),
            ),
          ],
        ),
        actionsWidget: [
          Container(
              alignment: Alignment.center,
              child: TextButton(
                onPressed: () {
                  Navigator.pop(context, 0);
                },
                child: Text(
                  '取消',
                  style: StylesUtils.customTextStyle(
                      color: ColorsUtils.color333, fontSize: Sizes.default16),
                ),
              )),
          Container(
              alignment: Alignment.center,
              child: TextButton(
                onPressed: () {
                  Navigator.pop(context, 1);
                },
                child: Text('确定',
                    style: StylesUtils.customTextStyle(
                        fontSize: Sizes.default16, color: ColorsUtils.colorFf6)),
              ))
        ],
        themeData: BrnDialogConfig(
            dialogWidth: 280,
            radius: Sizes.default10,
            titlePaddingSm: EdgeInsets.zero,
            titlePaddingLg: EdgeInsets.zero,
            contentPaddingSm: EdgeInsets.zero,
            contentPaddingLg: EdgeInsets.zero,
            contentTextAlign: TextAlign.center));
    int? result = await showDialog<int>(
      context: context,
      barrierDismissible: true,
      builder: (BuildContext context) {
        return dialog;
      },
    );
    if (result == 1) {
      /// 拨打电话
    }
  }

  void gotoView() {
    Get.toNamed(RouteGet.marketRecommendInfo);
  }
}
